#include "ahxgwnet.h"

namespace ahxgwnet {

ThreadMutex::ThreadMutex()
{
    pthread_mutex_init(&m_mutex, NULL);
}

ThreadMutex::~ThreadMutex()
{
    pthread_mutex_destroy(&m_mutex);
}

void ThreadMutex::lock()
{
    pthread_mutex_lock(&m_mutex);
}

void ThreadMutex::unlock()
{
    pthread_mutex_unlock(&m_mutex);
}

ThreadGuard::ThreadGuard(ThreadMutex *mutex)
{
    m_mutex = NULL;
    if (mutex)
    {
        m_mutex = mutex;
        m_mutex->lock();
    }
}

ThreadGuard::~ThreadGuard()
{
    if (m_mutex)
        m_mutex->unlock();
}

}
